package main

import (
	"bufio"
	"fmt"
	"net"
	"os"
)


func write(conn net.Conn){
	for{
		//从光标处读取
		reader := bufio.NewReader(os.Stdin)
		//读取数据直到换行
		content,_ := reader.ReadBytes('\n')
		//打印一下用户输入
		fmt.Println("客户发送的内容::",content)
		//发送用户输入内容
		conn.Write(content)
	}
}
func read(conn net.Conn){
	for{
		data := make([]byte,1024)
		n,_ := conn.Read(data)
		//读取服务端返回的数据并打印
		fmt.Println(">>>",string(data[:n]))
	}
}

func main() {
	conn,_ := net.Dial("tcp","127.0.0.1:8080")
	fmt.Println("client::",conn)
	defer conn.Close()

	go write(conn)
	read(conn)
}